{% for index_granularity in [999, 1000, 1001, 9999, 10000, 10001] -%}
-- { echoOn }

SELECT count() FROM url_na_log;
130000
SELECT rows FROM system.parts WHERE database = currentDatabase() AND table = 'url_na_log' AND active;
130000
SELECT count() FROM url_na_log PREWHERE DateVisit >= '2022-08-10' AND DateVisit <= '2022-08-20' WHERE SiteId = 209 SETTINGS max_block_size = 200000, max_threads = 1;
110000
-- Delete more than a half rows (60K)  from the range 2022-08-10 .. 2022-08-20
-- There should be 50K rows remaining in this range
DELETE FROM url_na_log WHERE SiteId = 209 AND DateVisit >= '2022-08-13' AND DateVisit <= '2022-08-18';
SELECT count() FROM url_na_log;
70000
SELECT rows FROM system.parts WHERE database = currentDatabase() AND table = 'url_na_log' AND active;
130000
SELECT count() FROM url_na_log PREWHERE DateVisit >= '2022-08-10' AND DateVisit <= '2022-08-20' WHERE SiteId = 209 SETTINGS max_block_size = 200000, max_threads = 1;
50000
-- Hide more than a half of remaining rows (30K) from the range 2022-08-10 .. 2022-08-20 using row policy
-- Now the this range should have 20K rows left
CREATE ROW POLICY url_na_log_policy0 ON url_na_log FOR SELECT USING DateVisit < '2022-08-11' or DateVisit > '2022-08-19' TO default;
SELECT count() FROM url_na_log;
40000
SELECT rows FROM system.parts WHERE database = currentDatabase() AND table = 'url_na_log' AND active;
130000
SELECT count() FROM url_na_log PREWHERE DateVisit >= '2022-08-10' AND DateVisit <= '2022-08-20' WHERE SiteId = 209 SETTINGS max_block_size = 200000, max_threads = 1;
20000
DROP ROW POLICY url_na_log_policy0 ON url_na_log;
{% endfor -%}
